/**
    入驻小区
**/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            shopSettingManageInfo: {
                shopSettings: [],
                settingTypes: [],
                total: 0,
                records: 1,
                moreCondition: false,
                shopId: '',
                conditions: {
                    shopId: vc.getCurrentCommunity().shopId,
                    settingName: '',
                    settingType: '',
                    settingKey: '',
                    settingValue: '',
                }
            }
        },
        _initMethod: function () {
            $that._listShopSettings(DEFAULT_PAGE, DEFAULT_ROWS);
            vc.getDict('shop_setting_key', "setting_type", function (_data) {
                $that.shopSettingManageInfo.settingTypes = _data;
            });
            vc.getDict('housekeeping_serv_pool', "state", function (_data) {

                console.log(_data);
            });
        },
        _initEvent: function () {

            vc.on('shopSettingManage', 'listShopSetting', function (_param) {
                $that._listShopSettings(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listShopSettings(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listShopSettings: function (_page, _rows) {

                $that.shopSettingManageInfo.conditions.page = _page;
                $that.shopSettingManageInfo.conditions.row = _rows;
                $that.shopSettingManageInfo.conditions.caId = vc.getCurrentCommunity().caId;
                var param = {
                    params: $that.shopSettingManageInfo.conditions
                };

                //发送get请求
                vc.http.apiGet('/shopSetting/queryShopSetting',
                    param,
                    function (json, res) {
                        var _shopSettingManageInfo = JSON.parse(json);
                        $that.shopSettingManageInfo.total = _shopSettingManageInfo.total;
                        $that.shopSettingManageInfo.records = _shopSettingManageInfo.records;
                        $that.shopSettingManageInfo.shopSettings = _shopSettingManageInfo.data;
                        vc.emit('pagination', 'init', {
                            total: $that.shopSettingManageInfo.records,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _openAddShopSettingModal: function () {
                vc.emit('addShopSetting', 'openAddShopSettingModal', {});
            },
            _openEditShopSettingModel: function (_shopSetting) {
                vc.emit('editShopSetting', 'openEditShopSettingModal', _shopSetting);
            },
            _openDeleteShopSettingModel: function (_shopSetting) {
                vc.emit('deleteShopSetting', 'openDeleteShopSettingModal', _shopSetting);
            },
            _queryShopSettingMethod: function () {
                $that._listShopSettings(DEFAULT_PAGE, DEFAULT_ROWS);

            },
            _resetCommunitySettingMethod: function () {
                $that.shopSettingManageInfo.conditions.settingType = "";
                $that.shopSettingManageInfo.conditions.settingName = "";
                $that.shopSettingManageInfo.conditions.settingKey = "";
                $that._listShopSettings(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _moreCondition: function () {
                if ($that.shopSettingManageInfo.moreCondition) {
                    $that.shopSettingManageInfo.moreCondition = false;
                } else {
                    $that.shopSettingManageInfo.moreCondition = true;
                }
            }


        }
    });
})(window.vc);
